package com.hzqy.web.ac;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hzqy.commons.utils.ConstantUtils;
import com.hzqy.service.label.LabelServiceBean;
import com.hzqy.web.vo.CmLabelVo;
import com.hzqy.web.vo.PmsUserVo;
import com.hzqy.web.vo.PmsZTreeVo;

@Controller
@RequestMapping("/")
public class LabelAction {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());

	@Resource
	private LabelServiceBean labelServiceBean;
	
	@RequestMapping("/label/label_list")
	@ResponseBody
	public Object resourceList(HttpSession session, ModelMap map, CmLabelVo clv) {
		PmsUserVo userVo = (PmsUserVo) session.getAttribute(ConstantUtils.SESSION_USER);
		List<PmsZTreeVo> ptv = new ArrayList<PmsZTreeVo>();
		ptv = labelServiceBean.selectLabelList(clv);
		return ptv;
	}
	
	@RequestMapping("/label/delete_label")
	@ResponseBody
	public Object deletelabel (int f_label_id) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = labelServiceBean.deleteLabel(f_label_id);
		resultMap.put("resultTitle", "删除结果");
		if(flag>0) {
			resultMap.put("success", true);
			resultMap.put("result","删除成功!");
		} else {
			resultMap.put("success", false);
			resultMap.put("result","删除失败!");
		}
		return resultMap;
	}
	
	@RequestMapping("/label/insert_label")
	@ResponseBody
	public Object insertlabel(HttpSession session,ModelMap map,CmLabelVo cmlabelVo) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = labelServiceBean.insertLabel(cmlabelVo);
		if(flag > 0) {
			resultMap.put("success", true);
			resultMap.put("result","新增内容成功!");
		} else {
			resultMap.put("success", true);
			resultMap.put("result","新增内容失败!flag="+flag);
		}
		return resultMap;
	}
	
	@RequestMapping("/label/select_label")
	@ResponseBody
	public Object selectlabel(int f_label_id) {
		CmLabelVo cmlabelVo = labelServiceBean.selectLabel(f_label_id);
		return cmlabelVo;
	}
	
	@RequestMapping("/label/update_label")
	@ResponseBody
	public Object updatelabel(CmLabelVo cmlabelVo) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = labelServiceBean.updateLabel(cmlabelVo);
		if(flag > 0) {
			resultMap.put("success", true);
			resultMap.put("result","修改内容成功!");
		} else {
			resultMap.put("success", true);
			resultMap.put("result","修改内容失败!flag="+flag);
		}
		return resultMap;
	}
}
